package com.wlz.rocketmq.simple;

import com.wlz.rocketmq.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultLitePullConsumer;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

/**
 * @author wlz
 * @date 2022-07-01  10:07 下午
 */
@Slf4j
public class LitePullConsumerSubscribe {

    public static volatile boolean running = true;

    public static void main(String[] args)throws Exception {
        DefaultLitePullConsumer consumer = new DefaultLitePullConsumer("lite_pull_consumer_test");

        consumer.setNamesrvAddr(Constants.NAMESVADDR);

        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

        consumer.subscribe("TopicTest", "*");

        consumer.start();

        try {
            while (running) {
                List<MessageExt> poll = consumer.poll();
                log.info(" poll : {} ", poll);
            }
        } catch (Exception e) {
            log.info("LitePullConsumerSubscribe error: {}", e);
        }


    }
}
